<?php
/**
 * @author Zwc
 * Created On 2021/5/3 17:04
 */

namespace app\auth\controller;


use app\auth\service\ConfigService;
use app\common\controller\AdminBaseController;
use think\App;

class Config extends AdminBaseController
{
    protected $service;
    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->service = new ConfigService();
    }

    public function index() {
        return view('index');
    }

    public function getData() {
        $data = $this->service->getData();
        return ['code' => 0,'msg' => '获取数据成功','data' => $data];
    }

    public function add() {
        if($this->request->isPost()) {
            $params = $this->request->post();
            $res = $this->service->addConfig($params);
            return $res;
        }else {
            return view('add',[
                'title' => '添加配置'
            ]);
        }
    }

    public function edit($id) {
        if($this->request->isPost()) {
            $params = $this->request->post();
            $res = $this->service->modifyConfig($params);
            return $res;
        }else {
            $detail = $this->service->detail($id);
            return view('edit',[
                'title' => '修改配置',
                'data' => $detail
            ]);
        }
    }
}